home *** CD-ROM | disk | FTP | other *** search
- /*
- A simple stand alone service example.
- It waits for connections on port 4000.
- After a connection is made,
- it waits for a string of max 256 char len and send it back reversed.
-
- To run it:
- - be sure TCP port 4000 is free (e.g. you don't have pserv.rexx
- enabled in inetd database, if you installed it).
- Open a shell and write:
- - rx revserv.
-
- To stop it:
- - CTRL_C in the shell where rvserv is running
- or
- - rx "shell 'REVSERVPORT' 'QUIT'"
- */
-
- prg = ProgramName("NOEXT")
-
- /**START libraries*/
- if ~show("L","rexxsupport.library") then
- if ~addlib("rexxsupport.library",0,-30) then call err "no rexxsupport.library"
-
- if ~show("L","rxsocket.library") then
- if ~addlib("rxsocket.library",0,-30) then call err "no rxsocket.library"
-
- if ~show("L","rmh.library") then
- if ~addlib("rmh.library",0,-30) then call err "no rmh.library"
- /**END libraries**/
-
- if ~Open("STDERR","*","W") | ~OpenPort("REVSERVPORT") then exit
-
- sock = socket("INET","STREAM","IP")
- if sock<0 then call err "can't create socket:" errno()
-
- local.ADDRFAMILY = "INET"
- local.ADDRADDR = 0
- local.ADDRPORT = 4000
- if bind(sock,"LOCAL")<0 then call err "can't bind port 4000:" errno()
-
- sig = PortSignal("REVSERVPORT")
- SEL.READ.0=sock
- open = 1
- do while open
-
- if Listen(sock,5)<0 then call err "listen error:" errno()
-
- res = WaitSelect("SEL",,,sig)
-
- pkt = GetPkt("REVSERVPORT")
- if pkt ~= null() then do
- comm= GetArg(pkt)
- call reply(pkt)
- if upper(comm) == "QUIT" then open = 0
- end
-
- if sel.0.read then do
-
- lsock = accept(sock,"REMOTE")
- if lsock<0 then call err "accept() error:" errno()
-
- auth = AuthFun(remote.addrAddr,4000,remote.addrPort)
- say auth
-
- len = recv(lsock,"BUF",256)
- if len>0 then do
- buf = reverse(buf)
- if send(lsock,buf) ~= length(buf) then call err "send() error:" errno()
- end
- if ( len < 0 ) & ( errno() ~= 35 )
- then call err "recv() error:" errno()
-
- call CloseSocket(lsock)
-
- end
-
- end
-
- exit
-
- err: procedure expose prg
- parse arg msg
- say prg":" msg
- exit
-
-